﻿Imports Oracle.DataAccess.Client
Public Class fListaTipoVendedor
    Dim lIdTipoVend As String
    Public ReadOnly Property idTipoVend() As String
        Get
            Return lIdTipoVend
        End Get
    End Property
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub consultar()
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        cmd.CommandText = "SELECT * FROM TER_TIPOVENDEDOR WHERE DESCRIPCION LIKE '%" & Me.txtDescripcion.Text & "%'"
        If Me.rbActivos.Checked Then
            cmd.CommandText &= " AND ESTADO=1"
        ElseIf Me.rbInactivos.Checked Then
            cmd.CommandText &= " AND ESTADO=2"
        End If
        Try
            DsTercero.TER_TIPOVENDEDOR.Rows.Clear()
            Conn.Open()
            DsTercero.TER_TIPOVENDEDOR.Load(cmd.ExecuteReader)
            Conn.Close()
            TER_TIPOVENDEDORDataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try

    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        Try
            consultar()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
    Private Sub AsignaTipoVendedor(ByVal Fila As Integer)
        If Fila >= 0 Then
            lIdTipoVend = TER_TIPOVENDEDORDataGridView.Rows(Fila).Cells("IDTIPOVENDEDOR").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub
    Private Sub TER_TIPOVENDEDORDataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles TER_TIPOVENDEDORDataGridView.CellMouseDoubleClick
        AsignaTipoVendedor(e.RowIndex)
    End Sub

    Private Sub TER_TIPOVENDEDORDataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TER_TIPOVENDEDORDataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaTipoVendedor(TER_TIPOVENDEDORDataGridView.CurrentRow.Index)
        End If
    End Sub

    Private Sub txtDescripcion_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDescripcion.KeyDown
        Try

            Select Case e.KeyCode
                Case 13
                    consultar()
            End Select
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
End Class